home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 80X86 / DOS32V33.ZIP / EXAMPLES / DLLTEST.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-11-27  |  3.2 KB  |  137 lines

  1. comment ~
  2. ****************************************************************************
  3. DLLTEST.ASM
  4.                 A basic example of using a DOS32 Loadable Library
  5.  
  6. Notes: As explained in the DOS32 documentaion, the use of the Library's
  7. global public symbol can be used in many differnet ways for the
  8. application to interfacing to/from the dynamic library. This example program
  9. will load the library file named A_DLL.DLL which contains a single
  10. two functions. The public in A_DLL.DLL will point to two pointer that
  11. refrence these two functions. See A_DLL.ASM (source of A_DLL.DLL).
  12.  
  13.  
  14. to compile:
  15.  
  16.  tasm dlltest
  17.  dlink dlltest
  18.  
  19. ****************************************************************************
  20. ~
  21. .386
  22. .model flat ,C
  23. .stack
  24. .code
  25.  
  26. ; varibles holding pointers to each function in A_DLL.DLL
  27. ;
  28. print_string    dd ?
  29. wait_for_key    dd ?
  30.  
  31.  
  32. message_1 db 'This message was printed from a procedure',13,10
  33.           db 'in the loadable library, A_DLL.DLL',13,10,36
  34. message_2 db 'press any key...',13,10,36
  35.  
  36.  
  37. dll_FileName db 'a_dll.dll',0
  38.  
  39. start:
  40.  
  41.   ;
  42.   ; Function EE10h to setup a DOS32 Dynamic Linkable Library file.
  43.   ;
  44.   ; Expects CS:EDX -> pointing to file name.
  45.   ;            EBX = seek position from beginning of file.
  46.   ;
  47.   ;
  48.     mov  ax,0EE10h
  49.     mov  edx, Offset dll_FileName
  50.     mov  ebx,0
  51.     int  31h
  52.     jnc  Ok
  53.     cmp  al,1                   ; if carry set then get error code from AL
  54.     je   error1                 ; 1 = file not found
  55.     cmp  al,2                   ; 2 = bad format
  56.     je   error2
  57. Ok:
  58.  
  59.   ; Returns EAX with number of bytes required to load the library.
  60.   ;         EBX = DLL file size
  61.  
  62.  
  63.   ;
  64.   ; Allocate memory for the loadable program.
  65.   ;
  66.     mov edx,eax
  67.     mov ax,0EE42h
  68.     int 31h
  69.     jc error
  70.  
  71.  
  72.   ;
  73.   ; Load the DLL
  74.   ;
  75.   ;      Expects CS:EDX -> pointing to memory block to holding
  76.   ;                         the DLL program.
  77.   ;
  78.     mov  ax,0EE11h
  79.     int  31h
  80.     jc error1
  81.  
  82.     ;
  83.     ; Returns CS:EDX -> pointing to the DLL public symbol.
  84.     ;
  85.     ; TEST.DLL is written so that the public symbol ('DOS32_DLL') points
  86.     ; to an array of pointers to each procedure.
  87.     ;
  88.  
  89.     mov     eax,[edx]             ; get first function pointer
  90.     mov     [print_string],eax
  91.     mov     eax,[edx+4]           ; get second function pointer
  92.     mov     [wait_for_key],eax
  93.  
  94.  
  95.    ; Use these two functions
  96.    ;
  97.  
  98.     mov     edx,Offset message_1
  99.     call    print_string
  100.  
  101.     mov     edx,Offset message_2
  102.     call    print_string
  103.  
  104.     call    wait_for_key
  105.  
  106.  
  107. exit:
  108.     mov ax,4c00h
  109.     int 21h
  110.  
  111.  
  112. ;---------------------------------------------------------------------
  113. error:
  114.     mov edx, offset error_mesg
  115.     mov ah,9
  116.     int 21h
  117.     jmp exit
  118. error_mesg db 'mot enough memory to load DLL',13,10,36
  119.  
  120. ;---------------------------------------------------------------------
  121. error1:
  122.     mov edx, offset error1_mesg
  123.     mov ah,9
  124.     int 21h
  125.     jmp exit
  126. error1_mesg db 'Error opening loadable library, TEST.DLL',13,10,36
  127.  
  128. ;-------------------------------------------------------------------
  129. error2:
  130.     mov edx, offset error2_mesg
  131.     mov ah,9
  132.     int 21h
  133.     jmp exit
  134. error2_mesg db 'Bad DOS32 Lodabale Library format',13,10,36
  135.  
  136.  
  137. end start